package com.sky.business.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sky.common.enums.Arch;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sky.business.sys.mapper.NodeMapper;
import com.sky.business.sys.domain.Node;
import com.sky.business.sys.service.NodeService;

import java.util.Date;
import java.util.List;
import java.util.Set;


@Service
public class NodeServiceImpl extends ServiceImpl<NodeMapper, Node> implements NodeService {

    @Override
    public List<Node> findByGroupAndLastHbAfterAndArchIn(Integer groupId, Date lastHeartbeat, Set<Arch> archList) {
        LambdaQueryWrapper<Node> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Node::getIsDel,false);
        queryWrapper.eq(Node::getGroupId,groupId);
        queryWrapper.gt(Node::getLastHeartBeatTime,lastHeartbeat);
        queryWrapper.eq(Node::getReady,true);
        queryWrapper.in(Node::getArch,archList);
        return getBaseMapper().selectList(queryWrapper);
    }

    @Override
    public List<Node> listUndelete() {
        LambdaQueryWrapper<Node> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Node::getIsDel,false);
        return getBaseMapper().selectList(queryWrapper);
    }
}
